package com.dyl.controller;

import com.dyl.entity.Student;
import com.dyl.service.StudentService;
import com.dyl.util.PageResult;
import com.dyl.util.R;
import com.dyl.vo.StudentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 类名：
 * 作者：DYL
 * 功能：
 */

@RestController
@RequestMapping("/student")
@CrossOrigin

public class StudentController {
    @Autowired
    private StudentService studentService;


    //学生列表
    @GetMapping("/list")
/*    public List<Student> findAll(){
        return studentService.list();*/
    public R findAll(){
        List<Student> list = studentService.list();
        return R.ok().data("list",list);
    }

    //分页查询
    @GetMapping("/findBypage/{page}/{pageSize}")
    public R findBypage(@PathVariable("page") Integer page,
                      @PathVariable("pageSize") Integer pageSize){
        PageResult<Student> pr = studentService.findByPage(page,pageSize);
            return R.ok().data("pr",pr);
}
//条件查询带分页
    @PostMapping("search/{page}/{pageSize}")
    public R search(@PathVariable("page") Integer page,
                    @PathVariable("pageSize") Integer pageSize,
                    @RequestBody(required = false) StudentVO vo){
        PageResult<Student> pr = studentService.search(page,pageSize,vo);
        return R.ok().data("pr",pr);
    }

}



